<%--
  Created by IntelliJ IDEA.
  User: yangtao
  Date: 2021-08-31
  Time: 13:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<div class="app-title">
    <div>
        <h1><i class="fa fa-floppy-o"></i> ${wellinfo.wellnum}井控案例详情</h1>
        <p></p>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="tile">
            <div class="row" style="justify-content: center;">
                <div class="col-lg-6">
                    <form>
                        <div class="form-group">
                            <label class="">井号</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.wellnum}" readonly>

                        </div>

                        <div class="form-group">
                            <label class="">所属单位</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.proprietor}" readonly>

                        </div>
                        <div class="form-group">
                            <label class="">区块名称</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.area}" readonly>
                        </div>
                        <div class="form-group">
                            <label>目的层岩性</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.mdcyx}" readonly>
                        </div>
                        <div class="form-group">
                            <label class="">目的层深度</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.mdcsd}" readonly>
                        </div>
                        <div class="form-group">
                            <label class="">目的层流体类型</label>
                            <input class="form-control" size="16" type="text" value="${wellinfo.mdcltlx}" readonly>
                        </div>
                        <div class="form-group">
                            <label class="control-label">开钻日期</label>
                            <div class="input-group"
                                 data-date-format="dd MM yyyy - HH:ii p">
                                <input class="form-control" size="16" type="text" value="${wellinfo.begindate}" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">完钻日期</label>
                            <div class="input-group " data-date=""
                                 data-date-format="dd MM yyyy - HH:ii p">
                                <input class="form-control" size="16" type="text" value="${wellinfo.enddate}" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="">防喷器安装情况</label>
                            <select class="form-control" disabled="disabled">
                                <option <c:if test="${fn:length(wellinfo.bopinstall)==0}">selected="selected"</c:if> value="">无</option>
                                <option <c:if test="${wellinfo.bopinstall==1}">selected="selected"</c:if> value="1">是</option>
                                <option <c:if test="${wellinfo.bopinstall==2}">selected="selected"</c:if> value="2">否</option>
                            </select>
                            <input type="hidden" id="bopinstall" value=""/>
                        </div>
                        <div class="form-group">
                            <label class="">防喷器试压情况</label>
                            <select class="form-control"  disabled="disabled">
                                <option <c:if test="${fn:length(wellinfo.boptest)==0}">selected="selected"</c:if> value="">无</option>
                                <option <c:if test="${wellinfo.boptest==1}">selected="selected"</c:if> value="1">正常</option>
                                <option <c:if test="${wellinfo.boptest==2}">selected="selected"</c:if> value="2">异常</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label class="">井控是否按照规定演习</label>
                            <select class="form-control" disabled="disabled">
                                <option <c:if test="${fn:length(wellinfo.controltest)==0}">selected="selected"</c:if> value="">无</option>
                                <option <c:if test="${wellinfo.controltest==1}">selected="selected"</c:if> value="1">是</option>
                                <option <c:if test="${wellinfo.controltest==2}">selected="selected"</c:if> value="2">否</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>固井质量</label>
                            <select class="form-control" disabled="disabled">
                                <option <c:if test="${fn:length(wellinfo.cemquality)==0}">selected="selected"</c:if> value="">无</option>
                                <option <c:if test="${wellinfo.cemquality==1}">selected="selected"</c:if> value="1">1</option>
                                <option <c:if test="${wellinfo.cemquality==2}">selected="selected"</c:if> value="2">2</option>
                                <option <c:if test="${wellinfo.cemquality==3}">selected="selected"</c:if> value="3">3</option>
                                <option <c:if test="${wellinfo.cemquality==4}">selected="selected"</c:if> value="4">4</option>
                                <option <c:if test="${wellinfo.cemquality==5}">selected="selected"</c:if> value="5">5</option>
                            </select>
                            <input type="hidden" id="cemquality" value=""/>
                        </div>
                        <div class="form-group">
                            <label class="">井别</label>
                            <select class="form-control" disabled="disabled">
                                <option <c:if test="${wellinfo.wellCategory.wellcategoryid==1}">selected="selected"</c:if> value="1">探井</option>
                                <option <c:if test="${wellinfo.wellCategory.wellcategoryid==2}">selected="selected"</c:if> value="2">开发井</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label class="">井型</label>
                            <select class="form-control" disabled="disabled">
                                <option <c:if test="${wellinfo.wellType.welltypeid==1}">selected="selected"</c:if> value="1">水平井</option>
                                <option <c:if test="${wellinfo.wellType.welltypeid==2}">selected="selected"</c:if> value="2">分支井</option>
                                <option <c:if test="${wellinfo.wellType.welltypeid==3}">selected="selected"</c:if> value="3">直井</option>
                                <option <c:if test="${wellinfo.wellType.welltypeid==4}">selected="selected"</c:if> value="4">定向井</option>
                            </select>
                        </div>
                    </form>
                </div>
            </div>
            <div class="tile-footer">
                <button class="btn btn-primary" type="button" onclick="save()">提交</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function getBack(){
        <%--${fn:length(wellinfo.wellCategory.wellcategoryid.toString())}--%>
        // window.location.href = document.referrer;
        $(".app-content").load("${ctx}/selectcase");
    }


    /*插入井信息的js*/
    $('.form_datetime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        keyboardNabigation: 1,
        pickerPosition: 'bottom-right'

    }).attr("data-date", new Date().toLocaleString());

    function checkValue(obj) {
        var object = $(obj);
        var elementValue = object.val();
        if (elementValue != null && elementValue != "") {
            object.addClass("is-valid").removeClass("is-invalid");
            object.parent().addClass("has-success").removeClass("has-danger");

        } else {
            object.addClass("is-invalid").removeClass("is-valid");
            object.parent().removeClass("has-success").addClass("has-danger");
        }
    }

    function selValue(object) {
        var obj = $(object);
        var selText = obj.find("option:selected").val();
        var selId = obj.next().attr("id");
        $("#"+selId).val(selText);
    }

    function isEmpty(obj) {
        if (typeof obj === 'undefined' || obj == null || obj === '') {
            return true;
        } else {
            return false;
        }
    }

    function saveIsEmpty(wellnum,proprietor,area,bopinstall,boptest,controltest,wellcategory,welltype) {
        if(isEmpty(wellnum&&proprietor&&area&&bopinstall&&bopinstall&&controltest&&wellcategory&&welltype)){
            return true;
        }
        return false;
    }


    function save() {
        var wellnum = $("#wellnum").val();
        var proprietor = $("#proprietor").val();
        var area = $("#area").val();
        var mdcyx = $("#mdcyx").val();
        var mdcsd = $("#mdcsd").val();
        var mdcltlx = $("#mdcltlx").val();
        var begindate = $("#begindate").val();
        var enddate = $("#enddate").val();
        var bopinstall = $("#bopinstall").val();
        var boptest = $("#boptest").val();
        var controltest = $("#controltest").val();
        var cemquality = $("#cemquality").val();
        var wellcategory = $("#wellcategory").val();
        var welltype = $("#welltype").val();

        var boo = saveIsEmpty(wellnum,proprietor,area,bopinstall,boptest,controltest,wellcategory,welltype);

        if(boo){
            swal({
                title: "请填写必填信息！",
                text: '带'+'<label class=""></label>'+'为必填项，请按照要求填写井的信息！',
                html:true,
                type: "warning",
                showCancelButton: false,
                confirmButtonText: "确认",
                closeOnConfirm: false
            });
            return false;
        }

        var wellinfo = {
            /*wellid: 0,*/
            wellnum: wellnum,
            proprietor: proprietor,
            area: area,
            mdcyx: mdcyx,
            mdcsd: mdcsd,
            mdcltlx: mdcltlx,
            begindate: begindate,
            enddate: enddate,
            bopinstall: bopinstall,
            boptest: boptest,
            controltest: controltest,
            cemquality: cemquality,
            wellCategory: {wellcategoryid: wellcategory},
            wellType: {welltypeid: welltype}

        };
        var well = JSON.stringify(wellinfo);
        $.ajax({
            url: '${ctx}/well/save',
            data: well,
            type: 'post',
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data == "success") {
                    swal({
                        title: "信息添加成功！",
                        text: "井:" + $("#wellnum").val() + "已成功添加至井控案例数据库。",
                        type: "success",
                        showCancelButton: false,
                        confirmButtonText: "确认",
                        closeOnConfirm: false
                    });
                    $(".app-content").load("${ctx}/dashboard");
                    $(".app-menu__item.active").removeClass("active");
                    $("#dashboarditem").addClass("active");
                }
                ;
            },
            error: function (data) {
                swal({
                    title: "信息添加失败！",
                    text: "井：" + $("#wellnum").val() + "未能成功添加至井控案例数据库。" + "\n" + "错误代码：" + data.status + "\n" + "错误信息：" + data.responseText,
                    html: false,
                    type: "error",
                    showCancelButton: false,
                    confirmButtonText: "确认",
                    closeOnConfirm: false
                });
            }
        });
    }
</script>